package com.innovate.nms.view;

import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

import com.innovate.nms.service.inspect.InspectTask;
import javax.swing.border.MatteBorder;
import java.awt.Color;

public class InspectTaskPanel extends JPanel implements ListCellRenderer<InspectTask> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -997400521903349333L;
	private JLabel lblIndex;
	private JLabel lblGoal;
	private JLabel lblState;
	private JLabel lblResult;

	/**
	 * Create the panel.
	 */
	public InspectTaskPanel() {
		setBorder(new MatteBorder(0, 0, 1, 0, (Color) Color.LIGHT_GRAY));
		setOpaque(false);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{10, 100, 320, 200, 400, 10, 0};
		gridBagLayout.rowHeights = new int[]{33, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		lblIndex = new JLabel("#");
		lblIndex.setFont(new Font("微软雅黑", Font.PLAIN, 24));
		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
		gbc_lblIndex.fill = GridBagConstraints.VERTICAL;
		gbc_lblIndex.insets = new Insets(0, 0, 0, 5);
		gbc_lblIndex.gridx = 1;
		gbc_lblIndex.gridy = 0;
		add(lblIndex, gbc_lblIndex);
		
		lblGoal = new JLabel("任务目标");
		lblGoal.setFont(new Font("微软雅黑", Font.PLAIN, 24));
		GridBagConstraints gbc_lblGoal = new GridBagConstraints();
		gbc_lblGoal.fill = GridBagConstraints.VERTICAL;
		gbc_lblGoal.anchor = GridBagConstraints.WEST;
		gbc_lblGoal.insets = new Insets(0, 0, 0, 5);
		gbc_lblGoal.gridx = 2;
		gbc_lblGoal.gridy = 0;
		add(lblGoal, gbc_lblGoal);
		
		lblState = new JLabel("状态");
		lblState.setFont(new Font("微软雅黑", Font.PLAIN, 24));
		GridBagConstraints gbc_lblState = new GridBagConstraints();
		gbc_lblState.fill = GridBagConstraints.VERTICAL;
		gbc_lblState.insets = new Insets(0, 0, 0, 5);
		gbc_lblState.gridx = 3;
		gbc_lblState.gridy = 0;
		add(lblState, gbc_lblState);
		
		lblResult = new JLabel("结果");
		lblResult.setFont(new Font("微软雅黑", Font.PLAIN, 24));
		GridBagConstraints gbc_lblResult = new GridBagConstraints();
		gbc_lblResult.insets = new Insets(0, 0, 0, 5);
		gbc_lblResult.fill = GridBagConstraints.VERTICAL;
		gbc_lblResult.anchor = GridBagConstraints.WEST;
		gbc_lblResult.gridx = 4;
		gbc_lblResult.gridy = 0;
		add(lblResult, gbc_lblResult);

	}

	@Override
	public Component getListCellRendererComponent(JList<? extends InspectTask> list, InspectTask value, int index,
			boolean isSelected, boolean cellHasFocus) {
		this.lblIndex.setText(String.format("%02d", value.getPorperty().get("index", Integer.class)));
		this.lblGoal.setText(value.goal());
		this.lblState.setText(value.getStateString());
		this.lblResult.setText(value.getResultString());
		return this;
	}

}
